package org.abc.fund.repository.funds;

import org.abc.fund.entity.funds.FundBasicInfo;
import org.abc.fund.entity.funds.FundTagRelation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface FundBasicInfoRepository extends JpaRepository<FundBasicInfo, String> {

    List<FundBasicInfo> findByCodeIn(List<String> codes);

    Page<FundBasicInfo> findByCodeIn(List<String> codes, Pageable pageable);

    List<FundBasicInfo> findByType(String type);

    Page<FundBasicInfo> findByType(String type, Pageable pageable);

    List<FundBasicInfo> findByOrderByLatestNavDesc();

    // ✅ 基金列表页关键词模糊搜索（基金名称 or 基金代码）
    Page<FundBasicInfo> findByNameContainingOrCodeContaining(String name, String code, Pageable pageable);

    // ✅ 基金经理页：根据经理名称模糊搜索分页
    Page<FundBasicInfo> findByManager_NameContaining(String managerName, Pageable pageable);

    // ✅ 基金公司页：根据公司名称模糊搜索分页
    Page<FundBasicInfo> findByCompany_NameContaining(String companyName, Pageable pageable);

    // ✅ 标签筛选 + 基金名称/代码模糊
    Page<FundBasicInfo> findByCodeInAndNameContainingOrCodeContaining(
            List<String> codes,
            String nameKeyword,
            String codeKeyword,
            Pageable pageable
    );

    // 🔍 根据基金经理姓名模糊查询基金列表（非分页）
    List<FundBasicInfo> findByManager_NameContaining(String managerName);

    //List<FundTagRelation> findByTagNameIn(List<String> tagNames);
    List<FundBasicInfo> findByCompany_NameContaining(String companyName);

    int countByManager_Name(String name);

    @Query("SELECT f.code FROM FundBasicInfo f")
    List<String> getAllFundCodes();
}

